home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / libraries / grab_globals.lib.php < prev    next >
PHP Script  |  2005-03-03  |  2KB  |  86 lines

  1. <?php
  2. /* $Id: grab_globals.lib.php,v 2.11 2005/03/03 20:59:24 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * This library grabs the names and values of the variables sent or posted to a
  8.  * script in the $_* arrays and sets simple globals variables from them. It does
  9.  * the same work for the $PHP_SELF, $HTTP_ACCEPT_LANGUAGE and
  10.  * $HTTP_AUTHORIZATION variables.
  11.  *
  12.  * loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
  13.  */
  14.  
  15. function PMA_gpc_extract($array, &$target, $sanitize = TRUE) {
  16.     if (!is_array($array)) {
  17.         return FALSE;
  18.     }
  19.     $is_magic_quotes = get_magic_quotes_gpc();
  20.     foreach ($array AS $key => $value) {
  21.         /**
  22.          * 2005-02-22, rabus:
  23.          *
  24.          * This is just an ugly hotfix to avoid changing internal config
  25.          * parameters.
  26.          *
  27.          * Currently, the following variable names are rejected when found in
  28.          * $_GET or $_POST: cfg, GLOBALS, str* and _*
  29.          */
  30.         if ($sanitize && is_string($key) && (
  31.             $key == 'cfg'
  32.             || $key == 'GLOBALS'
  33.             || substr($key, 0, 3) == 'str'
  34.             || $key{0} == '_')) {
  35.             continue;
  36.         }
  37.  
  38.         if (is_array($value)) {
  39.             // there could be a variable coming from a cookie of
  40.             // another application, with the same name as this array
  41.             unset($target[$key]);
  42.  
  43.             PMA_gpc_extract($value, $target[$key], FALSE);
  44.         } else if ($is_magic_quotes) {
  45.             $target[$key] = stripslashes($value);
  46.         } else {
  47.             $target[$key] = $value;
  48.         }
  49.     }
  50.     return TRUE;
  51. }
  52.  
  53. if (!empty($_GET)) {
  54.     PMA_gpc_extract($_GET, $GLOBALS);
  55. } // end if
  56.  
  57. if (!empty($_POST)) {
  58.     PMA_gpc_extract($_POST, $GLOBALS);
  59. } // end if
  60.  
  61. if (!empty($_FILES)) {
  62.     foreach ($_FILES AS $name => $value) {
  63.         $$name = $value['tmp_name'];
  64.         ${$name . '_name'} = $value['name'];
  65.     }
  66. } // end if
  67.  
  68. if (!empty($_SERVER)) {
  69.     $server_vars = array('PHP_SELF', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_AUTHORIZATION');
  70.     foreach ($server_vars as $current) {
  71.         if (isset($_SERVER[$current])) {
  72.             $$current = $_SERVER[$current];
  73.         } elseif (!isset($$current)) {
  74.             $$current = '';
  75.         }
  76.     }
  77.     unset($server_vars, $current);
  78. } // end if
  79.  
  80. // Security fix: disallow accessing serious server files via "?goto="
  81. if (isset($goto) && strpos(' ' . $goto, '/') > 0 && substr($goto, 0, 2) != './') {
  82.     unset($goto);
  83. } // end if
  84.  
  85. ?>
  86.